package simulador;

import Utils.Semente;
import eduni.simjava.Sim_entity;
import eduni.simjava.Sim_event;
import eduni.simjava.Sim_port;
import eduni.simjava.Sim_stat;
import eduni.simjava.Sim_system;
import eduni.simjava.distributions.ContinuousGenerator;
import eduni.simjava.distributions.Sim_negexp_obj;

public class Servidor extends Sim_entity{
	private Sim_port entrada;
	ContinuousGenerator geradorServicoServidor;
	
	public Servidor(String nome, double taxaServico) {
		super(nome);
        geradorServicoServidor = new Sim_negexp_obj("geradorServicoServidor", taxaServico, Semente.gera());
        entrada = new Sim_port("entrada");
        add_port(entrada);
        
		Sim_stat stat;
		stat = new Sim_stat();
		stat.add_measure(Sim_stat.ARRIVAL_RATE);
		stat.add_measure(Sim_stat.QUEUE_LENGTH);
		stat.add_measure(Sim_stat.RESIDENCE_TIME);
		stat.add_measure(Sim_stat.SERVICE_TIME);
		stat.add_measure(Sim_stat.THROUGHPUT);
		stat.add_measure(Sim_stat.UTILISATION);
		stat.add_measure(Sim_stat.WAITING_TIME);
		set_stat(stat);

	}
	
	public void body() {
	    while (Sim_system.running()) {
	      Sim_event e = new Sim_event();
	      sim_get_next(e);                 // Get the next event
	      sim_process(geradorServicoServidor.sample());              // Process the event
	      sim_completed(e);                // The event has completed service
	    }
	  }
}
